Skip to content

Conversation

RalfJung
Copy link
Member

Fixes #102043

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 25, 2022
@rust-highfive
Copy link
Contributor

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2022
@inquisitivecrystal inquisitivecrystal added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Sep 25, 2022
let existing_variants = adt.variants().iter().filter(|v| v.fields.is_empty()).count();
existing_variants > 1
/// Determines whether the given type is inhabited. `None` means that we don't know.
fn ty_inhabited(ty: Ty<'_>) -> Option<bool> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use tcx.type_uninhabited_from?

Copy link
Member Author

@RalfJung RalfJung Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Unfortunately the documentation is not helpful:

Computes the set of modules from which this type is visibly uninhabited. To check whether a type is uninhabited at all (not just from a given module), you could check whether the forest is empty.

Now I still don't know if this is an underapproximation or an overapproximation -- is this "definitely uninhabited" or "maybe uninhabited"? No idea which forest it is talking about.^^ 🌲

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type_uninhabited_from means definitely uninhabited. References and arrays of unknown length are considered inhabited by this query.

The "forest" is the query's return type, I agree this is esoteric. tcx.type_uninhabited_from(param_env.and(ty)).is_empty() means that ty is possibly inhabited (opposite of definitely uninhabited).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I can use is_ty_uninhabited_from as a nice wrapper.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and no then I need a module to check 'from'...

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 27, 2022

📌 Commit 67fd09d has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 27, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 27, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#101555 (Stabilize `#![feature(mixed_integer_ops)]`)
 - rust-lang#102253 (rustdoc: use CSS containment to speed up render)
 - rust-lang#102281 (make invalid_value lint a bit smarter around enums)
 - rust-lang#102284 (Structured suggestion for missing `mut`/`const` in raw pointer)
 - rust-lang#102330 (rustdoc: remove no-op CSS `.srclink { font-weight; font-size }`)
 - rust-lang#102337 (Avoid LLVM-deprecated `Optional::hasValue`)
 - rust-lang#102356 (session: remove now-unnecessary lint `#[allow]`s)
 - rust-lang#102367 (rustdoc: remove redundant `#help-button` CSS)
 - rust-lang#102369 (Fix search result colors)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8d2faa2 into rust-lang:master Sep 28, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 28, 2022
@RalfJung RalfJung deleted the invalid-enums branch September 30, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid_value misses some clearly bad enum initialization
6 participants